#include <cstdio>
#include <cstring>

const int maxn = 70;

int main() {
	char week[7][5] = {
		"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"
	};
	char one[maxn], two[maxn], three[maxn], four[maxn];
	scanf("%s", one);
	scanf("%s", two);
	scanf("%s", three);
	scanf("%s", four);

	int len1 = strlen(one);
	int len2 = strlen(two);
	int len3 = strlen(three);
	int len4 = strlen(four);
	int i;

	for (i = 0; i < len1 && i < len2; i++) {
		if (one[i] == two[i] && one[i] >= 'A' && one[i] <= 'G') {
			printf("%s ", week[one[i] - 'A']);
			break;		
		}
	}
	for (i++; i < len1 && i < len2; i++) {
		if (one[i] == two[i]) {
			if (one[i] >= '0' && two[i] <= '9') {
				printf("%02d:", one[i]-'0');
				break;
			} else if (one[i] >= 'A' && two[i] <= 'N') {
				printf("%02d:", one[i]-'A'+10);
				break;
			}
		}
	}

	for (i = 0; i < len3 && i < len4; i++) {
		if (three[i] == four[i]) {
			if ((three[i] <= 'z' && three[i] >= 'a') || (three[i] <= 'Z' && three[i] >= 'A')) {
				printf("%02d", i);
				break;
			}
		} 
	} 

	return 0;
}
